function decimalToBinary(decimal) {
    let binary = '';

    while (decimal > 0) {
        // 取余数
        binary = (decimal % 2) + binary;
        console.log(binary,typeof binary)
        // 对商取整
        decimal = Math.floor(decimal / 2);
    }

    // 如果输入的十进制数是0，直接返回'0'
    return binary || '0';
}

// 示例用法
let decimalNumber = 10;
let binaryNumber = decimalToBinary(decimalNumber);
console.log(`十进制数 ${decimalNumber} 的二进制表示是 ${binaryNumber}`);